Skip to content

fix(background-agent): preserve terminal tasks until notification cleanup#2367

Closed
code-yeongyu wants to merge 3 commits intodevfrom
fix/issue-2292
Closed

fix(background-agent): preserve terminal tasks until notification cleanup#2367
code-yeongyu wants to merge 3 commits intodevfrom
fix/issue-2292

Conversation

@code-yeongyu
Copy link
Owner

@code-yeongyu code-yeongyu commented Mar 7, 2026

Summary

  • keep session.error and session.deleted tasks in memory until the parent notification queue runs, so terminal tasks do not disappear before their result can be surfaced
  • move pending-parent cleanup to notification time so simultaneous completions only emit one final all-complete notification
  • skip terminal tasks during TTL pruning and cover the regressions with background-agent tests

Testing

  • bun test src/features/background-agent/
  • bun run typecheck
  • bun run build

Closes #2292


Summary by cubic

Fixes #2292 by keeping terminal and stale-pruned background tasks in memory until the parent notification runs, so results don’t disappear. Cleanup is deferred to notification time; TTL pruning skips terminal tasks and routes stale running tasks through a final notification.

  • Bug Fixes
    • Keep completed/error/cancelled/interrupt tasks until notifyParentSession runs.
    • Defer pendingByParent cleanup to notification; coalesce into one final “all complete” and clean even if promptAsync fails.
    • TTL pruning: skip terminal tasks; mark stale running tasks as error, notify parent, and delay cleanup.
    • On session.deleted: cancel descendants, remove toast entries, keep tasks and timers until delayed cleanup, and drop pending notifications for the deleted parent.

Written for commit d46946c. Summary will update on new commits.

Copy link

@cubic-dev-ai cubic-dev-ai bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No issues found across 4 files

Confidence score: 5/5

  • Automated review surfaced no issues in the provided summaries.
  • No files require special attention.

Requires human review: Moving cleanup to async notification paths and removing the TTL pruning safety net for terminal tasks could lead to memory leaks if timers or notifications fail to fire.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

BackgroundManager: tasks silently disappear during runtime (4 related bugs in task lifecycle)

1 participant